package com.qx.chat.system.message;

import java.util.Date;
import java.util.UUID;

import com.qx.chat.system.entity.ChatMessageRecord;
import com.qx.chat.system.event.Event;

public class Data<T> {

	

	private Date timestamp = new Date();

	private String type;

	private T data;

	public static Data<TextMessage> buildTextMessage(String msg, String from,
			String to) {
		TextMessage message = new TextMessage();
		message.setId(UUID.randomUUID().toString());
		message.setFrom(from);
		message.setTo(to);
		message.setMsg(msg);
		Data<TextMessage> data = new Data<TextMessage>();
		data.setType(TextMessage.TYPE);
		data.setData(message);
		return data;
	}
	public static Data<TextMessage> buildTextMessage(TextMessage message) {
		Data<TextMessage> data = new Data<TextMessage>();
		data.setType(TextMessage.TYPE);
		data.setData(message);
		return data;
	}
	public static Data<TextMessage> buildGroupTextMessage(TextMessage message) {
		Data<TextMessage> data = new Data<TextMessage>();
		data.setType(TextMessage.GROUPTYPE);
		data.setData(message);
		return data;
	}
	public static Data<TextMessage> buildSendTextMessage(TextMessage message) {
		Data<TextMessage> data = new Data<TextMessage>();
		data.setType(TextMessage.SENDTYPE);
		data.setData(message);
		return data;
	}
	public static Data<TextMessage> buildSendTextMessage(ChatMessageRecord cmr) {
		TextMessage message = new TextMessage();
		message.setId(cmr.getId());
		message.setFrom(cmr.getSpeakerUser().getLoginName());
		message.setFromName(cmr.getSpeakerUser().getNickname());
		message.setTo(cmr.getAudienceUser().getLoginName());
		message.setToName(cmr.getAudienceUser().getNickname());
		message.setMsg(cmr.getContentRtf());
		message.setChatType(ChatMessageRecord.USERMSGRECORD);
		message.setTime(cmr.getOccureTime());
		Data<TextMessage> data = new Data<TextMessage>();
		data.setType(TextMessage.SENDTYPE);
		data.setData(message);
		return data;
	}
	public static Data<TextMessage> buildSendGroupTextMessage(TextMessage message) {
		Data<TextMessage> data = new Data<TextMessage>();
		data.setType(TextMessage.SENDGROUPTYPE);
		data.setData(message);
		return data;
	}
	public static Data<TextMessage> buildSendGroupTextMessage(ChatMessageRecord cmr) {
		TextMessage message = new TextMessage();
		message.setId(cmr.getId());
		message.setFrom(cmr.getSpeakerUser().getLoginName());
		message.setFromName(cmr.getSpeakerUser().getNickname());
		message.setTo(cmr.getAudienceUser().getLoginName());
		message.setToName(cmr.getAudienceUser().getNickname());
		message.setMsg(cmr.getContentRtf());
		message.setGroupId(cmr.getAudienceGroupId());
		message.setGroupName(cmr.getAudienceGroup().getName());
		message.setChatType(ChatMessageRecord.GROUPMSGRECORD);
		message.setTime(cmr.getOccureTime());
		Data<TextMessage> data = new Data<TextMessage>();
		data.setType(TextMessage.SENDGROUPTYPE);
		data.setData(message);
		return data;
	}

	public static Data<Event> buildEventMessage(Event event) {
		Data<Event> data = new Data<Event>();
		data.setType(Event.TYPE);
		data.setData(event);
		return data;
	}

	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

}
